/**
 * <p>文件名:		CommonActionImpl.java</p>
 * <p>版权:		CopyrightTag</p>
 * <p>公司:		CompanyTag</p>
 * @author		周华彬(zhouhuabin@ctfo.com, zhou_hua_bin@163.com)
*/

package com.caits.lbs.framework.action;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.caits.lbs.framework.utils.FileUtils;
import com.caits.lbs.framework.utils.StringUtils;

/**
 * <p>CommonActionImpl</p>
 * <p>TODO</p>
 *
 * @author		周华彬(zhouhuabin@ctfo.com, zhou_hua_bin@163.com)
 * @version		0.0.0
 * <table style="border:1px solid gray;">
 * <tr>
 * <th width="100px">版本号</th><th width="100px">动作</th><th width="100px">修改人</th><th width="100px">修改时间</th>
 * </tr>
 * <!-- 以 Table 方式书写修改历史 -->
 * <tr>
 * <td>0.0.0</td><td>创建类</td><td>zhouhuabin</td><td>2014年10月14日 上午10:00:09</td>
 * </tr>
 * <tr>
 * <td>XXX</td><td>XXX</td><td>XXX</td><td>XXX</td>
 * </tr>
 * </table>
 */
public class CommonActionImpl extends BaseAction {

	/** TODO */
	private static final long serialVersionUID = 1L;

	/* (non-Javadoc)
	 * @see com.caits.lbs.framework.action.BaseAction#commonActionParser()
	 */
	@Override
	public void commonActionParser() {
		HttpServletRequest request =  getRequest();
		HttpServletResponse response = getResponse();
		response.setContentType(ContentTypeUtf8);
		OutputStream output = null;
		String result = null;
		try {
			output = response.getOutputStream();
			String rootPath = request.getSession().getServletContext().getRealPath("/");
			Map<String,String> paramMap = buildParamMap2String(request.getParameterMap());
			String pathInfo = request.getPathInfo();
			if(StringUtils.isNullOrBlank(pathInfo)){
				result = "代理服务缺少目标地址url参数";
				log.error(result);
				output.write(result.getBytes());
				return;//仍会执行finally代码
			}
			if(pathInfo.endsWith("xxxxx")){
				;
			}else if(pathInfo.endsWith("yyyyyy")){
				;
			}else{
				result = "不支持的服务,"+pathInfo;
				log.error(result);
				output.write(result.getBytes());
				return;//仍会执行finally代码
			}
		} catch (RuntimeException e) {
			result = "服务处理运行时错误,msg=" + e.getLocalizedMessage();
			log.error(result, e);
		}catch(Exception e){
			result= "服务处理错误,msg=" + e.getLocalizedMessage();
			log.error(result, e);
		}finally{
			try {
				if(result!=null){
					log.info("代理服务返回的结果：" + prettyStringLengh(result));
					output.write(result.getBytes(FileUtils.CONST_DEFAULT_CHARSET));
				}
				output.flush();
				output.close();
			} catch (IOException e) {
				log.error("服务输出结果错误,msg=" + e.getLocalizedMessage(), e);
			}// 返回相应结果
			
		}

	}

}
